package com.spring.appservice.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import com.fasterxml.jackson.databind.util.JSONPObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mangofactory.swagger.annotations.ApiIgnore;
import com.spring.appservice.web.service.MessageBoardService;
import com.spring.security.core.util.ApplicationUtils;

/**
 * 留言板
 * @author wojunyu
 *
 */
@Controller
@RequestMapping(value = "/messageBoard")
@ApiIgnore
public class MessageBoardController {
	
	@Resource
	private MessageBoardService messageBoardService;
	
	/**
	 * 获取留言列表
	 * @param token
	 * @param c_family_id
	 * @param request
	 * @param callback
	 * @return
	 
    @RequestMapping(value = "/queryMsgList")
    @ResponseBody
    public Object queryMsgList(String token,String c_family_id,
    		Integer pageNo,Integer pageSize,Integer skip,Integer row,
    		HttpServletRequest request,String callback) {
    	Map<String,Object> m = null;
    	try{
    		m = messageBoardService.queryMsgList(token,c_family_id,pageNo,pageSize,skip,row);
    	}catch(Exception e){
    		e.printStackTrace();
    		m = new HashMap<String,Object>();
    		m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
    	}
    	
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, m);
        }else{
        	return m;
        }
    }
    */
    /**
     * 获取留言及子留言
     * @param token
     * @param msg_id
     * @param request
     * @param callback
     * @return
     
    @RequestMapping(value = "/queryMsgDetailList")
    @ResponseBody
    public Object queryMsgDetailList(String token,String msg_id,
    		HttpServletRequest request,String callback) {
    	Map<String,Object> m = null;
    	try{
    		m = messageBoardService.queryMsgDetailList(token,msg_id);
    	}catch(Exception e){
    		e.printStackTrace();
    		m = new HashMap<String,Object>();
    		m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
    	}
    	
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, m);
        }else{
        	return m;
        }
    }
    */
    /**
     * 新增留言
     * @param token
     * @param msgBoard
     * @param request
     * @param callback
     * @return
     
    @RequestMapping(value = "/addMessageBoard")
    @ResponseBody
    public Object addMessageBoard(String token,MessageBoard msgBoard,
    		HttpServletRequest request,String callback) {
    	Map<String,Object> m = null;
    	try{
    		m = messageBoardService.addMessageBoard(token,msgBoard);
    	}catch(Exception e){
    		e.printStackTrace();
    		m = new HashMap<String,Object>();
    		m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
    	}
    	
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, m);
        }else{
        	return m;
        }
    }
    */
    
    /**
     * 删除留言及其子留言
     * @param token
     * @param msg_id
     * @param request
     * @param callback
     * @return
    
    @RequestMapping(value = "/removeMessageBoard")
    @ResponseBody
    public Object removeMessageBoard(String token,String msg_id,
    		HttpServletRequest request,String callback) {
    	Map<String,Object> m = null;
    	try{
    		m = messageBoardService.removeMessageBoard(token,msg_id);
    	}catch(Exception e){
    		e.printStackTrace();
    		m = new HashMap<String,Object>();
    		m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
    	}
    	
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, m);
        }else{
        	return m;
        }
    }
     */
	
	
	
	
	
	/**
	 * 得到总数
	 * @param token
	 * @param cUserID
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getCommunicationUnreadCount")
	@ResponseBody
	public Object getCommunicationUnreadCount(String token,String cUserID, String callback) {
		Map<String, Object> m = new HashMap();
		try {
			m = messageBoardService.getCommunicationUnreadCount(token, cUserID);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	
	
	
	
	/**
	 * 创建通道
	 * @param token
	 * @param msg_id
	 * @param request
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/createCommunication")
	@ResponseBody
	public Object createCommunication(String token,  String content, String password, 
			String communication, String callback) {
		Map<String, Object> m = new HashMap();
		try {
			m = messageBoardService.createCommunication(token, content, password, communication);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	/*
	 * 得到通道列表
	 */
	@RequestMapping(value = "/getCommunicationList")
	@ResponseBody
	public Object getCommunicationList(String token, String callback) {
		Map<String, Object> m = new HashMap();
		try {
			m = messageBoardService.getCommunicationList(token);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	/**
	 * 验证码密码
	 * @param token
	 * @param communicationID
	 * @param password
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/checkPassword")
	@ResponseBody
	public Object checkPassword(String token,String communicationID, String password, String callback) {
		Map<String, Object> m = new HashMap();
		try {
			m = messageBoardService.checkPassword(token, communicationID, password);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	 

	 /**
	  * 发送消息
	  * @param token
	  * @param content
	  * @param communication
	  * @param callback
	  * @return
	  */
	@RequestMapping(value = "/sendMassage")
	@ResponseBody
	public Object sendMassage(String token, String content, String communication, String callback) {
		Map<String, Object> m = new HashMap();
		try {
			m = messageBoardService.sendMassage(token, content, communication);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	

	/**
	 * 得到谈话内容	
	 * @param token
	 * @param communicationID
	 * @param page_size
	 * @param page_index
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getCommunicationContentList")
	@ResponseBody
	public Object getCommunicationContentList(String token, String communicationID, String page_size, 
			String page_index, String skip, String rows, String callback) {
		Map<String, Object> m = new HashMap();
		try {
			m = messageBoardService.getCommunicationContentList(token, communicationID, page_size, page_index, skip, rows);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	 
	
	
	@RequestMapping(value = "/getFutureMessageUnreadCount")
	@ResponseBody
	public Object getFutureMessageUnreadCount(String token, String cUserID, String callback) {
		Map<String, Object> m = new HashMap();
		try {
			m = messageBoardService.getFutureMessageUnreadCount(token, cUserID);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
			
	/**
	 * 创建给未来的信		
	 * @param token
	 * @param title
	 * @param content
	 * @param openTime
	 * @param user
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/createFutureMessage")
	@ResponseBody
	public Object createFutureMessage(String token, String title, String content, 
			String openTime, String user, String callback) {
		Map<String, Object> m = new HashMap();
		try {
			m = messageBoardService.createFutureMessage(token, title, content, openTime, user);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	
	/**
	 * 得到来自未来的信
	 * @param token
	 * @param page_size
	 * @param page_index
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getMyFutureMessageList")
	@ResponseBody
	public Object getMyFutureMessageList(String token, String page_size, String page_index,
			String skip, String rows, String callback) {
		Map<String, Object> m = new HashMap();
		try {
			m = messageBoardService.getMyFutureMessageList(token, page_size, page_index, skip, rows);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
	/**
	 * 得到来自未来的信内容
	 * @param token
	 * @param board_future_messageID
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getFutureMessageContent")
	@ResponseBody
	public Object getFutureMessageContent(String token, String board_future_messageID,String callback) {
		Map<String, Object> m = new HashMap();
		try {
			m = messageBoardService.getFutureMessageContent(token, board_future_messageID);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
}
